#include "wave.h"
#include "intrins.h"

void Delay12us(void)	//@12.000MHz
{
	unsigned char data i;

	_nop_();
	_nop_();
	i = 38;
	while (--i);
}

void wave_init()
{
	unsigned char i;
	for(i = 0;i < 8;i++)
	{
		P10 = 1;
		Delay12us();
		P10 = 0;
		Delay12us();
	}
}

unsigned char wave()
{
	unsigned int time;
	TMOD &= 0X0F;
	TH1 = TL1 = 0;
	wave_init();
	TR1 = 1;
	while((P11 == 1) && (TF1 == 0));
	TR1 = 0;
	if(TF1 == 0)
	{
		time = TH1 << 8 | TL1;
		return (time * 0.017);
	}
	else
	{
		TF1 = 0;
		return 0;
	}
}